<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            商品名称：<input type="text" name="productName"/>
                        </li>
                        <li>
                            状态：<input type="text" name="useStatus"/>
                        </li>
                        <li>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="channel:goodsInfo:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-success btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="channel:goodsInfo:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('channel:goodsInfo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('channel:goodsInfo:remove')}]];
    var prefix = ctx + "channel/goodsInfo";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "商品",
            sortName: "price",
            sortOrder: 'desc',
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'productId',
                    title: '商品id',
                    visible: false
                },
                {
                    field: 'productName',
                    title: '商品名称',
                    sortable: true
                },
                {
                    field: 'price',
                    title: '商品价格',
                    sortable: true
                },
                // {
                // 	field : 'clickCount',
                // 	title : '刷单总量限制',
                // 	sortable: true
                // },
                // {
                // 	field : 'totlaCount',
                // 	title : '当前已刷次数',
                // 	sortable: true
                // },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    },
                    title: '状态'
                },
                {
                    field: 'imgUrl',
                    title: '图片地址',
                    formatter: function (value, row, index) {
                        return '<img width="50" height="50" src="' + value + '" />';
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.productId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.productId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 状态显示 */
    function statusTools(row) {
        if (row.useStatus == 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.productId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.productId + '\')"></i> ';
        }
    }

    /* 用户管理启用 */
    function enable(productId) {
        $.modal.confirm("确认要启用吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"productId": productId, "useStatus": 0});
        })
    }

    /* 用户管理启用 */
    function disable(productId) {
        $.modal.confirm("确认要停用吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"productId": productId, "useStatus": 1});
        })
    }
</script>
</body>
</html>